
import java.util.Random;

import javax.swing.JOptionPane;

public class EventGenerator {

	public Event newEvent = new Event();
	
	// constructor
    public EventGenerator(int origPR) {
    	// Generate a random number with even distribution between 0 and 1
    	Random generator = new Random();
    	double r = generator.nextDouble();
    	
    	// Probability of 0.5
    	if (r < 0.5)
    	{
    		// calculate priority of the new event
    		int newPR = origPR + (3 * origPR);
    		newEvent.PR = newPR;
    		// enter info for the newly created event
    		//for now one string identifying which event occurs
    		newEvent.INF = JOptionPane.showInputDialog("0.5 Event 5-char INF: ");
    		if (newEvent.INF == null) { newEvent = null; }
    		else 
    		{
    			while(newEvent.INF.length()!=5)
		    	{
		    			newEvent.INF = JOptionPane.showInputDialog("Event INF can only be 5 chars ... try again:");
		    			if (newEvent.INF == null) { newEvent = null; }
	    		}
    		}
    		
    		newEvent.type = 1;
    	}
    	// Probability of 0.3
    	else if (r > 0.7)
    	{
    		// calculate priority of the new event
    		int newPR = origPR + (10 * origPR);
    		newEvent.PR = newPR;
    		// enter info for the newly created event
    		//for now one string identifying which event occurs
    		try 
    		{
    			newEvent.INF = JOptionPane.showInputDialog("0.3 Event 5-char INF: ");
    		}
    		catch (Exception e)
    		{
    			newEvent.type = -1;
    		}
    		while(newEvent.INF.length()!=5)
    		{
    			try 
        		{
        			newEvent.INF = JOptionPane.showInputDialog("Event Info can only be 5 chars ... try again:");
        		}
        		catch (Exception e)
        		{
        			newEvent.type = -1;
        		}
    		}
    		
    		newEvent.type = 2;
    		
    	}
    	// Remaining 0.2 probability
    	else
    	{
    		newEvent.type = -1;
    	}
    }
    
    public Event GetUserEvent()
    {
    	Event userEvent = new Event();
    	boolean invalid = false;
    	//get new user event priority
    	do 
    		try 
			{
    			userEvent.PR = Integer.parseInt(JOptionPane.showInputDialog("New Event Priority: "));
    			if (userEvent.PR < 1 || userEvent.PR > 200) { invalid = true; }
    			else { invalid = false; }
			}
    		catch (NumberFormatException e)
    		{
    			JOptionPane.showMessageDialog(null, "Event Priority must be an integer between 1 and 200");
    			invalid = true;
    		}
    	while (invalid == true);
    	
    	//get new user event INF
    	do 
    		try 
			{
    			userEvent.INF = JOptionPane.showInputDialog("New Event INF: ");
    			if (userEvent.INF.length() != 5) 
    			{ 
    				JOptionPane.showMessageDialog(null, "Event INF must be only 5 chars long.");
    				invalid = true; 
    			}
    			else { invalid = false; }
    			
			}
    		catch (NumberFormatException e)
    		{
    			JOptionPane.showMessageDialog(null, "Event Priority must be an integer between 1 and 200");
    			invalid = true;
    		}
    	while (invalid == true);
    	
    	userEvent.type = 3;
    	
    	return userEvent;
    }

	
}
